#include "MTXVector3.h"
using namespace MTX;

float Vector3::operator[] (const int i) const
{
	assert(i<3);
	return *(&x+i);
}

bool Vector3::operator== (const Vector3& w) const
{
	return x==w.x&&y==w.y&&z==w.z;
}

Vector3 Vector3::operator+ (const Vector3& w) const
{
	return Vector3(x+w.x,y+w.y,z+w.z);
}

Vector3 Vector3::operator- (const Vector3& w) const
{
	return Vector3(x-w.x,y-w.y,z-w.z);
}

float Vector3::operator* (const Vector3& w) const
{
	return x*w.x+y*w.y+z*w.z;
}

Vector3 Vector3::operator* (const float fScalar) const
{
	return Vector3(x*fScalar,y*fScalar,z*fScalar);
}

Vector3 Vector3::operator/ (const Vector3& w) const
{
	assert(w.x!=0&&w.y!=0&&w.z!=0);
	return Vector3(x/w.x,y/w.y,z/w.z);
}

Vector3 Vector3::operator/ (const float fScalar) const
{
	assert(fScalar!=0);
	return Vector3(x/fScalar,y/fScalar,z/fScalar);
}

Vector3& Vector3::operator+= (const Vector3& w)
{
	x+=w.x;
	y+=w.y;
	z+=w.z;
	return *this;
}

Vector3& Vector3::operator-= (const Vector3& w)
{
	x-=w.x;
	y-=w.y;
	z-=w.z;
	return *this;
}

Vector3& Vector3::operator*= (const Vector3& w)
{
	x*=w.x;
	y*=w.y;
	z*=w.z;
	return *this;
}

Vector3& Vector3::operator*= (const float fScalar)
{
	x*=fScalar;
	y*=fScalar;
	z*=fScalar;
	return *this;
}

Vector3& Vector3::operator/= (const Vector3& w)
{
	assert(w.x!=0&&w.y!=0&&w.z!=0);
	x/=w.x;
	y/=w.y;
	z/=w.z;
	return *this;
}

Vector3& Vector3::operator/= (const float fScalar)
{
	assert(fScalar!=0);
	x/=fScalar;
	y/=fScalar;
	z/=fScalar;
	return *this;
}

Vector3 Vector3::Cross(const Vector3& w) const
{
	return Vector3(x*w.x,y*w.y,z*w.z);
}

float Vector3::Dot(const Vector3& w) const
{
	return  x*w.x+y*w.y+z*w.z;
}

float Vector3::Length(void) const
{
	return sqrt(x*x+y*y+z*z);
}

bool Vector3::Normalized(void) const
{
	return Length()==1.0f;
}

void Vector3::Normailze(void)
{
	float len=Length();
	assert(len>0);
	x/=len;
	y/=len;
	z/=len;
}

float Vector3::Distance(const Vector3& w) const
{
	return (*this-w).Length();
}

bool Vector3::IsZeroLength(void) const
{
	return Length()==0.0f;
}